package com.kingint.web.admin.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kingint.common.unitedresult.K;
import com.kingint.mbg.bas.entity.SchedulingArrangement;
import com.kingint.mbg.bas.entity.vo.ScheArranVo;
import com.kingint.mbg.bas.mapper.SchedulingArrangementMapper;
import com.kingint.mbg.sys.entity.UmsMember;
import com.kingint.web.admin.base.service.SchedulingArrangementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kingint.web.sys.service.UmsAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 排版安排 服务实现类
 * </p>
 *
 * @author wxh
 * @since 2021-01-24
 */
@Service
public class SchedulingArrangementServiceImpl extends ServiceImpl<SchedulingArrangementMapper, SchedulingArrangement> implements SchedulingArrangementService {

    @Autowired
    private UmsAdminService umsAdminService;
    @Override
    public IPage<SchedulingArrangement> getpage(Page<SchedulingArrangement> page, SchedulingArrangement schedulingArrangement) {
        return baseMapper.getpagelist(page,schedulingArrangement);
    }

    @Override
    public List<ScheArranVo> getums(Integer hotel) {

        return baseMapper.getums(hotel);
    }

    @Override
    public Object getDateUms(String dateUms) throws ParseException {
        UmsMember currentMember = umsAdminService.getCurrentMember();
        if(StringUtils.isEmpty(currentMember.getHotelId())){
            return K.error().data("没登录");
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date frontStarTime=  dateFormat.parse(dateUms);
        QueryWrapper<SchedulingArrangement> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("hotel_id",currentMember.getHotelId()).eq("status",0);
        List<SchedulingArrangement> list = this.list(queryWrapper);
        List<Integer> integerList=new ArrayList<>();
        list.forEach(p->{
            if(p.getSchedulingDate().getTime()==frontStarTime.getTime()){
                integerList.add(p.getUmsId().intValue());
            }
        });


        return K.ok().data(integerList);
    }
}
